/*
 * @Author: wangjing wangjin122@qq.com
 * @Date: 2024-02-21 09:06:23
 * @LastEditors: wangjing wangjin122@qq.com
 * @LastEditTime: 2024-02-21 10:13:50
 * @FilePath: \code-rain\index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// const promise: Promise<string> = new Promise((r) => r("返回结果"))
// promise.then((res: string) => {
//   console.log(res)
// })

const canvas: HTMLCanvasElement = document.querySelector('canvas')
const ctx = canvas.getContext('2d')
canvas.width = screen.width
canvas.height = screen.height
const str: string[] = '0123456789'.split('')
const arr: Array<number> = Array(Math.ceil(canvas.width / 10)).fill(0)
const rain = () => {
  ctx.fillStyle = 'rgba(0,0,0,0.05)'
  ctx.fillRect(0,0,canvas.width,canvas.height)
  ctx.fillStyle = '#0f0'
  arr.forEach((item, index) => {
    ctx.fillText(str[Math.floor(Math.random() * str.length)], index * 10, item + 10)
    arr[index] = item > canvas.height || item > Math.random() * 15000 ? 0 : item + 10
  })
}
let timmer = setInterval(rain, 40)
canvas.onclick = () => {
  clearInterval(timmer)
}
canvas.ondblclick = () => {
  timmer = setInterval(rain, 40)
}
